package com.example.demo.controller;


import com.example.demo.entity.Appointment;
import com.example.demo.service.IAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 咨询者向咨询师发出的心理咨询预约 前端控制器
 * </p>
 *
 * @author hyb
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/appointment")
public class AppointmentController {
    @Autowired
    private IAppointmentService iAppointmentService; // 假设您有一个名为IAppointmentService的服务接口

    // 处理GET请求，获取预约列表
    @GetMapping("/list")
    public List<Appointment> list() {
        return iAppointmentService.list();
    }

    // 处理POST请求，创建新的预约
    @PostMapping("/create")
    public Appointment create(@RequestBody Appointment appointment) {
        iAppointmentService.save(appointment);
        return appointment;
    }

    // 根据ID查询预约信息
    @GetMapping("/{id}")
    public Appointment getAppointmentsById(@PathVariable Integer id) {
        return iAppointmentService.getById(id);
    }
}
